package com.cyt.web.controller.work.wb;

import cn.hutool.core.date.DateUtil;
import com.cyt.base.enums.BusinessType;
import com.cyt.base.enums.OperatorType;
import com.cyt.base.model.dto.ReturnResult;
import com.cyt.base.util.StringUtils;
import com.cyt.sys.aspect.BaseLog;
import com.cyt.sys.model.po.SysUser;
import com.cyt.web.controller.base.BaseController;
import com.cyt.work.wb.model.po.WbPjTarget;
import com.cyt.work.wb.model.vo.WbPjTargetVo;
import com.cyt.work.wb.service.WbPjTargetService;
import com.cyt.wx.model.po.WxEducationUser;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;

/**
 * 评价指标-wbPjTarget控制层
 *
 * @author dingxu
 * @date 2019-12-25 9:32:19
 */
@RestController
public class WbPjTargetController extends BaseController {

    @Resource
    private WbPjTargetService wbPjTargetService;

    /**
     * 统一跳转
     *
     * @return Model
     * @author dingxu
     * @date 2019-12-25 9:32:19
     */
    @RequestMapping("/work/wb/wbpjtarget/{pageName}")
    public ModelAndView goPage(@PathVariable("pageName") String pageName, String applyId) {
        ModelAndView view = new ModelAndView("/work/wb/wbpjtarget/"+pageName);
        view.addObject("applyId", applyId);
        return view;
    }

    /**
     * 分页查询
     *
     * @param wbPjTargetVo 接受参数对象
     * @param page 当前页面
     * @param limit 页面数量
     * @return ReturnResult
     * @author dingxu
     * @date 2019-12-25 9:32:19
     */
    @BaseLog(module = "评价指标", classz = "wbPjTarget", methods = "分页查询对象", businessType = BusinessType.GET, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/wb/wbpjtarget/page", method = RequestMethod.POST)
    public ReturnResult page(WbPjTargetVo wbPjTargetVo, int page, int limit) {
        return wbPjTargetService.page(wbPjTargetVo, page, limit);
    }

    /**
     * 跳转添加或编辑界面
     *
     * @param id 主键
     * @return ReturnResult
     * @author dingxu
     * @date 2019-12-25 9:32:19
     */
    @BaseLog(module = "评价指标", classz = "wbPjTarget", methods = "跳转添加或编辑界面", businessType = BusinessType.GET, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/wb/wbpjtarget/getEdit", method = RequestMethod.GET)
    public ModelAndView getEdit(String id) {
        ModelAndView view = new ModelAndView("/work/wb/wbpjtarget/wbPjTargetEdit");
        if (StringUtils.isNotBlank(id)) {
            view.addObject(wbPjTargetService.selectByPrimaryKey(id));
        }
        return view;
    }

    /**
     * 保存或更新
     *
     * @param request 请求对象
     * @param wbPjTargetVo 接受参数对象
     * @return ReturnResult
     * @author dingxu
     * @date 2019-12-25 9:32:19
     */
    @BaseLog(module = "评价指标", classz = "wbPjTarget", methods = "保存或更新对象", businessType = BusinessType.INSERT, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/wb/wbpjtarget/addOrUpdate", method = RequestMethod.POST)
    public ReturnResult addOrUpdate(HttpServletRequest request, WbPjTargetVo wbPjTargetVo) {
        return wbPjTargetService.addOrUpdate(wbPjTargetVo, acceptCurrentUser(request));
    }

    /**
     * 根据条件逻辑删除
     *
     * @param request 请求对象
     * @param wbPjTargetVo 接受参数对象
     * @return ReturnResult
     * @author dingxu
     * @date 2019-12-25 9:32:19
     */
    @BaseLog(module = "评价指标", classz = "wbPjTarget", methods = "逻辑删除对象", businessType = BusinessType.DELETE, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/wb/wbpjtarget/remove", method = RequestMethod.GET)
    public ReturnResult remove(HttpServletRequest request, WbPjTargetVo wbPjTargetVo) {
        return wbPjTargetService.remove(wbPjTargetVo, acceptCurrentUser(request));
    }

    /**
     * 更新状态
     * @param request
     * @param id
     * @param status
     * @author congcong tao
     * @date 2019/9/6 15:35
     */
    @BaseLog(module = "评价指标", classz = "wbPjTarget", methods = "更新状态", businessType = BusinessType.UPDATE, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/wb/wbpjtarget/updateStatus", method = RequestMethod.POST)
    public ReturnResult updateStatus(HttpServletRequest request, String id, String status) {
        SysUser sysUser = acceptCurrentUser(request);
        WbPjTarget wbPjTarget=wbPjTargetService.selectByPrimaryKey(id);
        wbPjTarget.setValidState(status);
        wbPjTarget.setUpdateTime(new Date());
        wbPjTarget.setUpdateUser(sysUser.getId());
        wbPjTargetService.updateByPrimaryKey(wbPjTarget);
        return new ReturnResult();
    }

    /**
     * 根据条件物理删除
     *
     * @param request 请求对象
     * @param wbPjTargetVo 接受参数对象
     * @return ReturnResult
     * @author dingxu
     * @date 2019-12-25 9:32:19
     */
    @BaseLog(module = "评价指标", classz = "wbPjTarget", methods = "物理对象对象", businessType = BusinessType.DELETE, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/wb/wbpjtarget/delete", method = RequestMethod.GET)
    public ReturnResult delete(HttpServletRequest request, WbPjTargetVo wbPjTargetVo) {
        return wbPjTargetService.delete(wbPjTargetVo, acceptCurrentUser(request));
    }
}